/*
 *
 *  ------------------------------------------------------------------
 *  Copyright © 2017 Hangzhou DtDream Technology Co.,Lt d. All rights reserved.
 *  ------------------------------------------------------------------
 *        Product:  EMR
 *    Module Name: NEZHA
 *   Date Created: 17-10-23 下午4:22
 *    Description:
 *  ------------------------------------------------------------------
 *  Modification History
 *  DATE            Name           Description
 *  ------------------------------------------------------------------
 *  2017-10-23      NEZHA EMR
 *  ------------------------------------------------------------------
 * /
 */

package org.xukai.remoting.sdk.web.api.serde;

import com.dtdream.emr.common.NeZhaResponse;
import com.dtdream.emr.common.Page;
import com.dtdream.emr.common.codec.JacksonCodec;
import com.dtdream.emr.sql.metadata.TableDesc;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import java.io.IOException;

/**
 * Created by moriarty on 17-6-13.
 */
public class GetTablesPagedSerDe extends HttpSerDe<Page> {

    public GetTablesPagedSerDe() {
        super(Page.class);
    }

    @Override
    public RequestBody serialize() throws IOException {
        return null;
    }

    @Override
    public Page<TableDesc> deserialize(ResponseBody body) throws IOException {
        JavaType innerType = TypeFactory.defaultInstance()
                .constructParametricType(Page.class, TableDesc.class);
        NeZhaResponse<?> response = JacksonCodec.deserialize(body.charStream(), NeZhaResponse.class,
                innerType);
        assertNeZhaResponseNotNull(response);
        return (Page<TableDesc>) response.getBody();
    }
}
